<template>
  <el-row justify="end">
    <div id="effect-login-window">
      <el-form>
        <el-form-item label="账 号">
          <el-input v-model="form.mobile"></el-input>
        </el-form-item>
        <el-form-item label="账 号">
          <el-input v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="login" :loading="loading">{{ loading ? loginText : '登录' }}</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-row>

</template>
<script setup>
import { ipcApiRoute } from '@/api/main';
import { ipc } from '@/utils/ipcRenderer';
import { useRouter } from 'vue-router';
import { ref, reactive } from 'vue'
import axios from 'axios';

const router = useRouter()
const loading = ref(false)
const loginText = ref('正在登录......')

const form = reactive({
  mobile: '19900000004',
  password: '123456',
  usertype: 2
});

const login = () => {
  try {
    loading.value = true
    // axios.post('http://218.77.108.2:8082/zb-api/api/login', {
    //   ...form
    // }).then(res => {
    //   console.log(res);
    //   localStorage.setItem('token', res.data.data.token);
    //   // this.$router.push({ name: 'DigitalHuman', params: {}});
      
    // })
    router.push({ name: 'LiveRooms', params: {} });
    loading.value = false

    initServer()
  } catch (error) {
    console.log(error);
  }
}

// 数字人服务初始化
const initServer = async () => {
  const batPath = 'D:\\dh-runtime/socket-server.bat'
  const res = await ipc.invoke(ipcApiRoute.startCmd, batPath)
  console.log("启动socket服务----", res)

  if (res) {
    const voiceServerBat = 'D:\\dh-runtime/queue_infer_api/app_Service.bat'
    const rst = await ipc.invoke(ipcApiRoute.startCmd, voiceServerBat)
    console.log("启动音频服务----", rst)
  }
}
</script>
<style lang="less" scoped>
#effect-login-window {
  width: 400px;
  min-height: 600px;
  border-radius: 12px;
  background: #f0f2f5;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>